package com.chagee.store.operation.server.service.third;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.chagee.base.utils.*;
import com.chagee.storeManagement.api.event.request.OperateRecordRequest;
import com.chagee.storeManagement.api.event.request.QueryOperateRecordInfoRequest;
import com.chagee.storeManagement.api.event.response.BasePageResponse;
import com.chagee.storeManagement.api.event.response.QueryStoreOperateRecordResponse;
import com.chagee.storeManagement.api.event.service.StoreServiceApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author : hk
 * @Date : 2025/3/19
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class StoreThirdService {

	@Resource
	private StoreServiceApi storeServiceApi;


	public Boolean addOperateRecord(OperateRecordRequest request) {
		try {
			log.info("StoreThirdService.addOperateRecord,request:{}", JSONUtil.toJsonStr(request));
			SoaResponse<Boolean, Void> response = storeServiceApi.addOperateRecord(request);
			log.info("StoreThirdService.addOperateRecord,response:{}", JSONUtil.toJsonStr(response));
			Boolean result = SoaUtil.unpack(response);
			return result;
		} catch (Exception e) {
			log.error("StoreThirdService.addOperateRecord,request:{},error:", JSONUtil.toJsonStr(request), e);
			return false;
		}
	}

	public BasePageResponse<QueryStoreOperateRecordResponse> queryRecordByStoreNoAndRecordType(PaginationRequest<QueryOperateRecordInfoRequest> request) {
		try {
			log.info("StoreThirdService.queryRecordByStoreNoAndRecordType,request:{}", JSONObject.toJSONString(request));
			SoaResponse<BasePageResponse<QueryStoreOperateRecordResponse>, Void> response = storeServiceApi.queryOperateRecordPage(request);
			log.info("StoreThirdService.queryRecordByStoreNoAndRecordType,response:{}", JSONObject.toJSONString(response));
			BasePageResponse<QueryStoreOperateRecordResponse> list = SoaUtil.unpack(response);
			return list;
		} catch (Exception e) {
			log.error("StoreThirdService.queryStoreOperateRecord,request:{},error:", JSONObject.toJSONString(request), e);
			return new BasePageResponse<>();
		}
	}
}
